//
//  AboutUsViewController.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/14.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "AboutUsViewController.h"
#import "Masonry.h"
#import "SeverviceSecurtViewController.h"
#import "GPosAPI.h"
#import "SVProgressHUD.h"
#import "XMRegisterViewController.h"
@interface AboutUsViewController ()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) UIView *backgroundViews;
@property (nonatomic,strong) UIImageView *iconView;
@property (nonatomic,strong) UILabel *versonLab;
@property (nonatomic,strong) UIView *serviceView;
@property (nonatomic,strong) UILabel *serviceLab;
@property (nonatomic,strong) UIView *currentVerson;
@property (nonatomic,strong) UIView *versonPull;
@property (nonatomic,strong) UILabel *currentLab;
@property (nonatomic,strong) UILabel *versonLabs;
@property (nonatomic,strong) NSString *version;
@property (nonatomic,strong) NSDictionary *dataDic;
@end

@implementation AboutUsViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    //去掉返回的文字
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title=@"关于我们";
   
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
-(void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataDic=[[NSDictionary alloc] init];
    int userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary * dic =[NSDictionary dictionaryWithObjectsAndKeys:@(userId),@"userId",@(2),@"device", nil];
    __weak typeof(self) weakSelf = self;
    [GPosAPI requestVersonWithParams:dic andCallback:^(id obj) {
        
        if (obj==nil)
        {
            
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            [weakSelf initUI];
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                
                weakSelf.dataDic=[obj objectForKey:@"data"];
                
                [self initUI];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            else{
                
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                [weakSelf initUI];
            }
        }
        
    }];
    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    
}

-(void)initUI{
    NSLog(@"%@",self.dataDic);
    self.backgroundViews=[[UIView alloc] init];
    self.backgroundViews.backgroundColor=[UIColor colorWithWhite:0.94 alpha:1];
    [self.view addSubview:self.backgroundViews];
    [self.backgroundViews mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(kNavbarHeight);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight));
        
    }];
    
    self.iconView = [[UIImageView alloc] init];
    self.iconView.image=[UIImage imageNamed:@"icon_tubiao"];
    [self.backgroundViews addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.backgroundViews.mas_top).offset(46);
    make.left.equalTo(self.backgroundViews.mas_left).offset(KmainScreenWidth/2-73/2);
        make.width.and.height.equalTo(@(73));
        
    }];
    
    self.versonLab = [[UILabel alloc] init];
    if ([self.dataDic count]==0) {
        self.versonLab.text=@"";
    }else{
    self.versonLab.text = [NSString stringWithFormat:@"v%@",[self.dataDic objectForKey:@"versionName"]];
    }
    self.versonLab.textColor = [UIColor blackColor];
    self.versonLab.textAlignment = NSTextAlignmentCenter;
    [self.backgroundViews addSubview:self.versonLab];
    [self.versonLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.iconView.mas_bottom).offset(16);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(20));
        
    }];
    
    self.serviceView = [[UIView alloc] init];
    self.serviceView.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.serviceView];
    [self.serviceView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.backgroundViews.mas_top).offset(195);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(52));
    }];
    
    self.serviceLab = [[UILabel alloc] init];
    self.serviceLab.text = @"服务及隐私条款";
    self.serviceLab.font=[UIFont systemFontOfSize:15];
    UITapGestureRecognizer *tp=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tpViews:)];
    tp.delegate=self;
    [self.serviceView addGestureRecognizer:tp];
    [self.serviceView addSubview:self.serviceLab];
    [self.serviceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.serviceView.mas_top).offset(15);
        make.left.equalTo(self.serviceView.mas_left).offset(15);
        make.right.equalTo(self.serviceView.mas_right).offset(-70);
        make.bottom.equalTo(self.serviceView.mas_bottom).offset(-15);
        
    }];
    UIImageView *rightV=[[UIImageView alloc] init];
    rightV.image = [UIImage imageNamed:@"icon_jt_you"];
    [self.serviceView addSubview:rightV];
    [rightV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.serviceView.mas_top).offset(18);
        make.right.equalTo(self.serviceView.mas_right).offset(-25);
    }];
    
    self.currentVerson = [[UIView alloc] init];
    self.currentVerson.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.currentVerson];
    [self.currentVerson mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.serviceView.mas_bottom).offset(10);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(52));
        
    }];
    UILabel *labOne=[[UILabel alloc] init];
    labOne.text = @"当前版本";
    labOne.font = [UIFont systemFontOfSize:15];
    [self.currentVerson addSubview:labOne];
    [labOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.currentVerson.mas_top).offset(15);
        make.left.equalTo(self.currentVerson.mas_left).offset(15);
        make.right.equalTo(self.currentVerson.mas_right).offset(-90);
        make.bottom.equalTo(self.currentVerson.mas_bottom).offset(-15);
    }];
    
    self.currentLab = [[UILabel alloc] init];
    self.currentLab.textAlignment = NSTextAlignmentCenter;
    if ([self.dataDic count]==0)
    {
       self.currentLab.text = @"";
    }else{
        
        self.currentLab.text = [NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"versionName"]];
    }
    
    self.currentLab.font=[UIFont systemFontOfSize:13];
    [self.currentVerson addSubview:self.currentLab];
    [self.currentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.currentVerson.mas_top).offset(15);
        make.left.equalTo(self.serviceLab.mas_right).offset(10);
        make.right.equalTo(self.currentVerson.mas_right).offset(-5);
        make.bottom.equalTo(self.currentVerson.mas_bottom).offset(-15);
        
    }];
    /*
    self.versonPull = [[UIView alloc] init];
    self.versonPull.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.versonPull];
    [self.versonPull mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.currentVerson.mas_bottom).offset(1.3);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(52));
        
    }];
    
    UILabel *labTwo=[[UILabel alloc] init];
    labTwo.text = @"版本更新";
    labTwo.font = [UIFont systemFontOfSize:15];
    [self.versonPull addSubview:labTwo];
    [labTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.versonPull.mas_top).offset(15);
        make.left.equalTo(self.versonPull.mas_left).offset(15);
        make.right.equalTo(self.versonPull.mas_right).offset(-150);
        make.bottom.equalTo(self.versonPull.mas_bottom).offset(-15);
    }];
    
    self.versonLabs = [[UILabel alloc] init];
    self.versonLabs.textAlignment = NSTextAlignmentRight;
    self.versonLabs.text = @"暂无更新";
    self.versonLabs.font = [UIFont systemFontOfSize:13];
    [self.versonPull addSubview:self.versonLabs];
    [self.versonLabs mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.versonPull.mas_top).offset(15);
        make.left.equalTo(labTwo.mas_right).offset(10);
        make.right.equalTo(self.versonPull.mas_right).offset(-8);
        make.bottom.equalTo(self.versonPull.mas_bottom).offset(-15);
        
    }];
    */
}
-(void)tpViews:(UIGestureRecognizer *)tp{
    
    SeverviceSecurtViewController *vc=[[SeverviceSecurtViewController alloc] init];
    
    vc.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
